1. Technical Field
This invention generally relates to computer programming and more specifically relates to mechanisms and methods for debugging a computer program.
2. Background Art
Since the dawn of the computer age, computer systems have evolved into extremely sophisticated devices, and computer systems may be found in many different settings. Computer systems typically include a combination of hardware, such as semiconductors and circuit boards, and software, also known as computer programs. As advances in semiconductor processing and computer architecture push the performance of the computer hardware higher, more sophisticated computer software has evolved to take advantage of the higher performance of the hardware, resulting in computer systems today that are much more powerful than just a few years ago.
As the sophistication and complexity of computer software increase, the more difficult the software is to debug. Debugging is the process of finding problems, or xe2x80x9cbugsxe2x80x9d, during the development of a computer program. Most modern programming environments include a debugger that provides tools for testing and debugging a computer program. Many debuggers allow detecting when an exception is generated in the computer program.
An exception is typically generated when the computer program requires special processing. Some exceptions occur as part of the normal operation of a computer program. For example, if a communication error is detected, an exception could be generated to automatically request a re-send of the data without the user ever knowing that an error or exception occurred. This type of error could be termed an expected error, because the program has code for processing this error. However, other exceptions may occur that the program does not anticipate, that may indicate a bug in the program. Thus, it is important to distinguish between exceptions that are part of normal program processing (i.e., that are caused by an anticipated error condition), and exceptions that signal unexpected error conditions.
Some computer programming languages, like Java developed by Sun Microsystems, provide explicit try-catch instructions. In debugging a computer program, when a programmer suspects an unexpected error may occur in processing a particular block of code, the programmer can insert a xe2x80x9ctryxe2x80x9d instruction at the beginning of the block and a xe2x80x9ccatchxe2x80x9d instruction at the end which will catch any exceptions that might occur during the execution of the block of code. Note, however, that the block of code may include calls to other methods or procedures which in turn could make calls to other methods or procedures, and this can continue for an arbitrary depth. Exceptions may be generated at various levels within the suspicious block of code. Some of these exceptions may be expected exceptions that are handled at various levels below the block of code with the try-catch instructions. In defining a try-catch block of code in a debug mode, the programmer may not be interested in all exceptions that are generated, but only those that actually flow all the way up to the block of code where the try-catch logic resides (i.e., those that are not xe2x80x9chandledxe2x80x9d at lower levels).
Known debuggers allow the programmer to set one or more breakpoints in the computer program, which are points where the execution of the computer program is stopped so that the state of the program can be examined to verify that the program executed as designed. Breakpoints can also be generated when an exception occurs. However, as explained above, many exceptions in a computer program are expected exceptions, and do not signal a bug in the computer program. If a programmer specifies that a debugger break on exceptions, the debugger will generate a breakpoint for each exception, expected or not. If there is a great deal of normal exception processing, this results in the programming halting numerous times, even though no error has occurred. Without a mechanism and method for distinguishing between exceptions that are expected and those that are not, the computer industry will continue to suffer from inefficient methods and tools for debugging computer programs.
According to the preferred embodiments of the present invention, an apparatus and method allow dynamically defining exception handlers in a debugger and breaking only when one of the dynamically-defined exception handlers is activated. In this manner a programmer can define special exception handlers referred to herein as debugger exception handlers that correspond to exceptions of interest while debugging, and can thus distinguish between exceptions that are expected (and therefore handled) in a computer program and exceptions that signal a bug in the computer program during debugging.